// enhance the shadow of a DOM element
function enhanceShadow(element) {
  element.style.boxShadow = "0 0 50px 5px black";
}

// reduce the shadow of a DOM element
function reduceShadow(element) {
  element.style.boxShadow = "";
}

// cut the message to get a complete sentence
function cutMessage(message) {
  for (i=message.length-1; i>0; i--) {
    if (message[i]==='.' || message[i]==='?' || message[i]==='!')
      return message.substr(0,i+1);
  }
  return message;
}

// numeral p1 is under d from p2
function tooClose (p1, p2, d) {
  if(Math.abs(p1-p2)<d)
    return true;
  else return false;
}

// delete the post collection
function deleteCollection(collection) {
  for (i=0;i<collection.length;i++) {
    collection.remove(collection.models[i]);
  }
}

// create a line with CSS3, with pixels (cannot be used with percent placement)
function createLine(x1,y1, x2,y2) {
  var length = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
  var angle  = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI;
  var transform = 'rotate('+angle+'deg)';

    var line = $('<div>')
        .appendTo('#line-container')
        .addClass('line')
        .css({
          'position': 'absolute',
          'webkit-transform': transform,
          'transform': transform,
          'z-index': 20,
          'left': x1+'%',
          'top': y1+'%',
        })
        .width(length)

    return line;
}